package nl.zuiderfestival.raydance.model.zones;

import java.awt.Dimension;
import java.awt.Point;
import java.io.Serializable;
import java.util.Observable;

public class Zone extends Observable implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	private int id;
	private Point location;
	private Dimension size;
	
	private boolean enabled;
	
	public Zone(int id, Point location, Dimension size) {
		super();
		this.id = id;
		this.location = location;
		this.size = size;
		this.setEnabled(false);
	}

	public Point getLocation() {
		return location;
	}

	public void setLocation(Point location) {
		this.location = location;
		setChanged();
		notifyObservers();
	}

	public Dimension getSize() {
		return size;
	}

	public void setSize(Dimension size) {
		this.size = size;
		setChanged();
		notifyObservers();
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
	
	public String toString() {
		return ""+id;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		//this looks funny and it is, because location gets updated alot, the setChanged is true.
		//there for we only want to notify the observers with argument if enabled flag changed.
		boolean changed = this.enabled != enabled;
		if (changed) {
			setChanged();
		}
		this.enabled = enabled;
		if (changed) {
			notifyObservers(this);
		}
	}

	public boolean isIn(double x, double y) {
		boolean result = false;
		if (x>=location.x && x <= location.x + size.width) {
			if (y>=location.y && y <= location.y + size.height) {
				result = true;
			}
		}
		return result;
	}
}
